






	<cfquery name = "to" datasource="exp">
	SELECT id, condid
	FROM trial
	WHERE expid = 3 
	</cfquery>
	
	<cfquery name ="co" datasource="exp">
	SELECT DISTINCT condid
	FROM trial
	WHERE expid=3
	</cfquery>
	
	
	
	
	
	
	
	
	
	<!--- recordCount is a built in function that will return the number of records that meet the query's spec --->
	<cfset numTri = #to.recordCount#>
	<cfset numCon = #co.recordCount#>
	<cfset numBlo = numTri / numCon>


	<cfloop index="i" from="1" to="#numCon#" step="1">
		<cfif #to.condid# eq #i#>
		

    <!--- Create an array. --->
    <cfset arrTri = ArrayNew( 1 ) /> 
    <!--- Resize the array to be our test number. --->
    <cfset ArrayResize( arrTri, #numTri# ) /> 
    <!--- Now, we need to populate the array with data. --->
    <cfloop index="i" from="1" to="#numTri#" step="1">
    
    <!--- QUERIES --->
    <cfquery name="tricon" datasource="exp">
    SELECT condid
    FROM trial
    WHERE expid = 3, id = #to.id#
    
    
    <!--- Create a struct for the data, Set the ID to be the index. --->
    <cfset arrTri[ i ] = StructNew() />
    <cfset arrTri[ i ].ID = i />
    <cfset arrTri[ i ] = StructNew() />
    <cfset arrTri[ i ].C = i />
    </cfloop>
    <!--- Loop over the array N times. --->
   	<cfloop index="j" from="1" to="#ArrayLen( arrTri )#" step="1">
   	<!--- Swap the current item with a randomly chosen item. We are getting the random index via RandRange(). --->
   	<cfset ArraySwap(arrTri, j, RandRange( 1, ArrayLen( arrTri ) ) ) />
   	</cfloop>
   	
   	
   	<cfloop index="i" from="1" to="#numCon#" step="1">
   		
	
	<cfoutput>	
	number of trials : #numTri# <br/>
	number of unique conditions : #numCon# <br/>
	number of blocks : #numBlo# <br/>

	Random order of trials :
    <cfloop from="1" to="#ArrayLen(arrTri)#" index="i">
    <td> #arrTri[i].ID#</td>
    </cfloop>
    
	</cfoutput>
	
	